<?php
	class taisanthechapdb
	{
		public function Them($SoHDTC = "",
							 $MaKH = "", 
							$NguoiThuaKe = "",
							$NgaySinh = "",
							$DiaChi = "",
							$SoCMND = "",
							$NgayCap = "",
							$NoiCap = "",
							 $SoQSDD = "",
							 $NoiCapDat = "",
						     $NgayCapDat = "",
							 $ThuaDatSo = "",
							 $MaDiaBan = "",
							 $ToBanDoSo = 0,
							 $TongDienTich = 0,
							 $GiaTriTaiSan = 0,
							 $MucChoVay = 0)
		{
			$sql = "INSERT INTO taisanthechap(SoHDTC, MaKH, NguoiThuaKe, NgaySinh, DiaChi, SoCMND, NgayCap, NoiCap, SoQSDD, NoiCapDat, NgayCapDat, ThuaDatSo, MaDiaBan, ToBanDoSo, TongDienTich, GiaTriTaiSan, MucChoVay)
					VALUES('$SoHDTC',
							 '$MaKH',
							 '$NguoiThuaKe',
							 '$NgaySinh', 
							 '$DiaChi',
							 '$SoCMND',
							 '$NgayCap',
							 '$NoiCap',
							 '$SoQSDD', 
							 '$NoiCapDat',
							 '$NgayCapDat',
							 '$ThuaDatSo',
							 '$MaDiaBan',
							 $ToBanDoSo,
							 $TongDienTich,
							 $GiaTriTaiSan,
							 $MucChoVay)";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($SoHDTC = "",						    
								$NguoiThuaKe = "",
								$NgaySinh = "",
								$DiaChi = "",
								$SoCMND = "",
								$NgayCap = "",
								$NoiCap = "")
		{
			$sql = "UPDATE taisanthechap SET 
			NguoiThuaKe = '$NguoiThuaKe',
			NgaySinh = '$NgaySinh',
			DiaChi = '$DiaChi',
			SoCMND = '$SoCMND',
			NgayCap = '$NgayCap',
			NoiCap = '$NoiCap'";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($SoHDTC = "",
							 		$MaKH = "",
									$NguoiThuaKe = "",
									$NgaySinh = "",
									$DiaChi = "",
									$SoCMND = "",
									$NgayCap = "",
									$NoiCap = "",
									$SoQSDD= "", 
							 		$NoiCapDat = "",
						     		$NgayCapDat = "",
							 		$ThuaDatSo = "",
							 		$MaDiaBan = "",
							 		$ToBanDoSo = 0,
							 		$TongDienTich = 0,
									$GiaTriTaiSan = 0,
									$MucChoVay = 0)
		{
			$sql = "SELECT * 
					FROM taisanthechap
					WHERE (1)";
			
			if($SoHDTC != "")
				$sql .= " AND SoHDTC = '$SoHDTC'";
			
			if($MaKH != "")
				$sql .= " AND MaKH = '$MaKH'";	

			if($NguoiThuaKe != "")
				$sql .= " AND NguoiThuaKe = '$NguoiThuaKe'";
				
			if($NgaySinh != "")
				$sql .= " AND NgaySinh = '$NgaySinh'";
				
			if($DiaChi != "")
				$sql .= " AND DiaChi = '$DiaChi'";
				
			if($SoCMND != "")
				$sql .= " AND SoCMND = '$SoCMND'";
				
			if($NgayCap != "")
				$sql .= " AND NgayCap = '$NgayCap'";
				
			if($NoiCap != "")
				$sql .= " AND NoiCap = '$NoiCap'";
			
			if($SoQSDD != "")
				$sql .= " AND SoQSDD = '$SoQSDD'";
			
			if($NoiCapDat != "")
				$sql .= " AND NoiCapDat = '$NoiCapDat'";
			
			if($NgayCapDat != "")
				$sql .= " AND NgayCapDat = '$NgayCapDat'";
			
			if($ThuaDatSo != "")
				$sql .= " AND ThuaDatSo = '$ThuaDatSo'";
			
			if($MaDiaBan != "")
				$sql .= " AND MaDiaBan = '$MaDiaBan'";
				
			if($ToBanDoSo > 0)
				$sql .= " AND ToBanDoSo = $ToBanDoSo";
			
			if($TongDienTich > 0)
				$sql .= " AND TongDienTich = $TongDienTich";
			
			if($GiaTriTaiSan > 0)
				$sql .= " AND GiaTriTaiSan = $GiaTriTaiSan";
			
			if($MucChoVay > 0)
				$sql .= " AND MucChoVay = $MucChoVay";

			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>